package com.lw.edu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lw.edu.entity.Course;
import com.lw.edu.entity.frontvo.CourseWebVo;
import com.lw.edu.entity.vo.CoursePublishVo;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;

public interface CourseMapper extends BaseMapper<Course> {
    @Select( "SELECT ec.id,ec.title,ec.price,ec.lesson_num,et.name as teacher_name,ec.cover,es1.title as subject_level_two,es2.title as subject_level_one FROM edu_course ec LEFT JOIN edu_subject es1 on ec.subject_id=es1.id LEFT JOIN edu_subject es2 on ec.subject_parent_id = es2.id LEFT JOIN edu_teacher et on ec.teacher_id=et.id WHERE ec.id=#{id}" )
    @ResultType( CoursePublishVo.class )
    public CoursePublishVo getCoursePublishInfo(String courseId);

    @Select( "SELECT ec.id,ec.title,ec.price,ec.lesson_num,ec.buy_count,ec.view_count,ecd.description,ec.cover," +
            "et.id as teacherId,et.name as teacher_name,et.intro,et.avatar," +
            "es1.title as subject_level_two,es1.id as subject_level_two_id," +
            "es2.title as subject_level_one,es2.title as subject_level_one_id " +
            "FROM edu_course ec LEFT JOIN edu_subject es1 on ec.subject_id=es1.id " +
            "LEFT JOIN edu_subject es2 on ec.subject_parent_id = es2.id " +
            "LEFT JOIN edu_teacher et on ec.teacher_id=et.id " +
            "LEFT JOIN edu_course_description ecd on ec.id = ecd.id " +
            "WHERE ec.id=#{id}" )
    @ResultType( CourseWebVo.class )
    CourseWebVo getBaseCourseInfo(String id);
}
